package Negocio;

import Datos.DBHistorial;
import Entidades.Historial;
import Interfaces.IHistorial;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;
import Entidades.Autos;
import Entidades.Mecanico;
import Entidades.Service;
import Entidades.Ventas;
import javax.swing.DefaultComboBoxModel;

public class DAOHistorial implements IHistorial {

    DBHistorial a = new DBHistorial();
    DAOAutos b = new DAOAutos();
    DAOService c = new DAOService();
    DAOMecanico d = new DAOMecanico();
    DAOVentas e = new DAOVentas();
    public DefaultTableModel modelo = new DefaultTableModel();
    ArrayList<Historial> lista = a.ListaHistorial();

    @Override
    public boolean IngresaHistorial(Historial nodo) {
        return a.IngresaHistorial(nodo);
    }

    @Override
    public boolean ModificaHistorial(Historial nodo) {
        return a.ModificaHistorial(nodo);
    }

    @Override
    public boolean EliminaHistorial(int IDHistorial) {
        return a.EliminaHistorial(IDHistorial);
    }

    @Override
    public ArrayList<Historial> ListaHistorial() {
        return a.ListaHistorial();
    }

    @Override
    public DefaultTableModel ModeloHistorial() {
    modelo = new DefaultTableModel();
        modelo = new javax.swing.table.DefaultTableModel(
                new Object[][]{},
                new String[]{
                    "ID", "NroUnidad", "IDVenta", "IDService", "IDMecanico"
                }){boolean[] canEdit = new boolean [] {
                false, true, true, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }};   
        int i=0;
        while(i<lista.size()){
            String Id = Integer.toString(lista.get(i).getIDHistorial());
            String Nu = Integer.toString(lista.get(i).getNroUnidad());
            String Idv = Integer.toString(lista.get(i).getIDVenta());
            String Ids = Integer.toString(lista.get(i).getIDService());
            String Idm = Integer.toString(lista.get(i).getIDMecanico());
            String[] vector = {Id, Nu, Idv, Ids, Idm};
            modelo.addRow(vector);
            i++;
        }
        return modelo;
    }
    
    public DefaultComboBoxModel cargoNu(){
        int x =0;
        ArrayList<Autos> aut = b.ListaAutos();
        String[] autito = new String[aut.size()];
        while (x <aut.size()){
            autito[x]=Integer.toString(aut.get(x).getNroUnidad());
            x++;
        }
        DefaultComboBoxModel model = new DefaultComboBoxModel(autito);
        return model;
    }
    
    
    public DefaultComboBoxModel cargoIdv(){
        int x =0;
        ArrayList<Ventas> vt = e.ListaVentas();
        String[] ventass = new String[vt.size()];
        while (x <vt.size()){
            ventass[x]=Integer.toString(vt.get(x).getIDVenta());
            x++;
        }
        DefaultComboBoxModel model = new DefaultComboBoxModel(ventass);
        return model;
    }
    
    
    public DefaultComboBoxModel cargoIds(){
        int x =0;
        ArrayList<Service> sv = c.ListaService();
        String[] servicee = new String[sv.size()];
        while (x <sv.size()){
            servicee[x]=Integer.toString(sv.get(x).getIDService());
            x++;
        }
        DefaultComboBoxModel model = new DefaultComboBoxModel(servicee);
        return model;
    }
    
    public DefaultComboBoxModel cargoIdm(){
        int x =0;
        ArrayList<Mecanico> mc = d.ListaMecanico();
        String[] mechanic = new String[mc.size()];
        while (x <mc.size()){
            mechanic[x]=Integer.toString(mc.get(x).getIDMecanico());
            x++;
        }
        DefaultComboBoxModel model = new DefaultComboBoxModel(mechanic);
        return model;
    }

}
